<cfscript>
	// Inherit downwards. I feel like there's an easier way to do this
	param name="URL.username" default="";
	param name="FORM.username" default="#URL.username#";
	param name="URL.code" default="";
	param name="FORM.code" default="#URL.code#";

	REQUEST.login = EntityLoad("mySCF", {Username = FORM.username}, true);

	// If the login in question doesn't exist
	if(!isDefined("REQUEST.login")){ Location("../index.cfm", false, 302); }

	// If the login in question doesn't need activation
	if(REQUEST.login.getStatus()){ Location("../index.cfm", false, 302); }

	if(FORM.code NEQ ""){
		if(TRIM(FORM.code) EQ Hash(REQUEST.login.getSalt(), 'MD5')){
			REQUEST.login.setStatus(1);
			EntitySave(REQUEST.login);
			ORMFlush();

			SESSION.MySCF = StructNew();
			SESSION.MySCF.MySCFID = REQUEST.login.getMySCFID();
			SESSION.MySCF.Username = REQUEST.login.getUsername();
			if(isDefined("SESSION.MySCFApplication")){
				REQUEST.app = SESSION.MySCFApplication;
				StructDelete(SESSION, "MySCFApplication");
				Location(REQUEST.app, false, 302);
			} else {
				Location("../secure", false, 302);
			}
		} else {
			REQUEST.ERROR = "Invalid activation code";
		}
	}
</cfscript>
<html>
	<head>
		<title>MySCF Activation</title>
		<style type="text/css">
			* { font-family: Verdana, Geneva, Arial, Helvetica, sans-serif; }
			body { text-align: center; }
			p { margin: auto; font-size: 14px; width: 500px; }
			div.e { color: #f00; }
		</style>
		<script type="text/javascript" src="/jquery/jquery-1.4.2.min.js"></script>
		<script type="text/javascript">
			$(function(){ $('input[name="code"]').focus(); });
		</script>
	</head>
	<body>
		<p>
			Thank you for signing up. You should receive an email shortly
			with an activation code. In order to finish the signup process,
			you must provide that code in the box below. Alternatively,
			you may click on the included link and the code will be
			submitted automatically.

			<br/><br/>

			<cfoutput>
			<form method="post" action="activate.cfm">
				<input type="hidden" name="username"
					value="#HTMLEditFormat(FORM.username)#">

				Activation Code: <input type="text" name="code" size="30" />
				<input type="submit" name="submitbtn" value="Submit" />
				<br/><br/>
				<cfif isDefined("REQUEST.ERROR")>
					<div class="e">#REQUEST.ERROR#</div>
				</cfif>
			</form>
			</cfoutput>
		</p>
	</body>
</html>